use core::{fmt::Display, result};

#[derive(Debug)]
#[allow(clippy::upper_case_acronyms)]
pub enum KallocError {
    ENOMEM,
    EORDER,
    EALLOCED,
    ECHECK,
    ENOTAIL,
    ENOCOMP,
}

pub type Result<T> = result::Result<T, KallocError>;

impl Display for KallocError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        let error = match self {
            Self::ENOMEM => "Out of memory",
            Self::EORDER => "Order invalid",
            Self::EALLOCED => "Alloced",
            Self::ECHECK => "Check at free flag(s) set",
            Self::ENOTAIL => "PageTail not set",
            Self::ENOCOMP => "Comp head not consistent",
        };
        write!(f, "{}", error)
    }
}
